package cn.wen.mybatis.framework.builder;


import cn.wen.mybatis.framework.mapping.BoundSql;
import cn.wen.mybatis.framework.mapping.ParameterMapping;
import cn.wen.mybatis.framework.mapping.SqlSource;
import cn.wen.mybatis.framework.session.Configuration;

import java.util.List;

/**
 * 静态sql语句维护类
 * select * from post order by id
 * StaticSqlSource 表示不带有占位符且可能会包含 ? 的sql语句，如：
 * StaticSqlSource表示持有不包含 #{} 和 ${} 占位符的sql
 */
public class StaticSqlSource implements SqlSource {

  private final String sql;
  private final List<ParameterMapping> parameterMappings;
  private final Configuration configuration;

  public StaticSqlSource(Configuration configuration, String sql) {
    this(configuration, sql, null);
  }

  public StaticSqlSource(Configuration configuration, String sql, List<ParameterMapping> parameterMappings) {
    this.sql = sql;
    this.parameterMappings = parameterMappings;
    this.configuration = configuration;
  }

  @Override
  public BoundSql getBoundSql(Object parameterObject) {
    return new BoundSql(configuration, sql, parameterMappings, parameterObject);
  }

}
